<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>FTM网上商城后台</title>
<link rel="stylesheet" href="css_cz/layui/css/layui.css">
<link rel="stylesheet" href="css_cz/css/global.css">
<link rel="stylesheet" href="css_cz/icheck/minimal/red.css">

</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<!-- 顶部栏和左侧菜单栏 -->
		<jsp:include page="MenuBar.html"></jsp:include>

		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div style="padding: 15px;">
				<fieldset class="layui-elem-field">
					<legend>请填写管理员信息</legend>
					<div class="layui-field-box">
						<div
							class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
							<div class="container-fluid">
								<div class="row-fluid">
									<div class="span8">
										<form class="form-horizontal" action="BackstageServlet"
											method="post" onsubmit="return check()">
											<!-- 提示区域 -->
											<%=request.getAttribute("msg") == null ? "" : request.getAttribute("msg")%>
											<div class="control-group">
												<label class="control-label" for="inputadminuser">用户名</label>
												<div class="controls">
													<input type="text" name="adminuser" id="adminuser" />
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="inputPassword">密码</label>
												<div class="controls">
													<input type="password" name="adminpw" />
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="inputPassword">确认密码</label>
												<div class="controls">
													<input type="password" name="adminpw2" />
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="inputname">姓名</label>
												<div class="controls">
													<input type="text" name="adminname" />
												</div>
											</div>
											<div class="control-group">
												<div class="controls">

													<!-- 在JSP中记录一个随机数，称为令牌（token），存储在session中 -->
													<%
														session.setAttribute("token", System.nanoTime() + "");
													%>
													<!-- ajax检查 并显示提示语句 -->
													<span id="msg"></span></br>
													<!-- 将token值作为表单的一个隐藏域 -->
													<input type="hidden" name="token"
														value="<%=session.getAttribute("token")%>"> <input
														type="hidden" name="op" value="addadmin"></br>
													<button type="submit" class="btn">提交</button>
												</div>
											</div>
										</form>
									</div>
									<div class="span4"></div>
								</div>
							</div>
						</div>
					</div>
				</fieldset>
			</div>
		</div>

		<div class="layui-footer">
			<!-- 底部固定区域 -->
			页脚
		</div>
	</div>
	
	<script type="text/javascript" src="css_cz/javascript/jquery.min.js"></script>
	<script type="text/javascript" src="css_cz/layui/layui.js"></script>
	<script type="text/javascript" src="css_cz/javascript/index.js"></script>
	<script src="css_cz/layui/layui.js"></script>
	
	<script>
		//标记一下ajaxName是否执行
		var msg = "";
		$(function() {
			//离开文本框判断是否重复
			$("#adminuser").blur(function() {
				ajaxName();

			});
		});

		function ajaxName() {
			$.ajax({
				//key:value
				url : "BackstageServlet",
				type : "get",
				data : {
					adminuser : $("#adminuser").val(),
					op : "ajaxadminname"
				},
				success : function(data) {
					console.log("data->msg: " + data);
					msg = data;
					$("#msg").html(data);
				},
				dataType : "json"

			});
		};

		function check() {
			//提交判断
			if (msg == "用户名不存在,可以使用！") {
				console.log("data->msg: " + msg);
				return true;
			} else {
				console.log("data->msg: " + msg);
				return false;
			}
		}
	</script>
</body>
</html>